
package com.example.xunai.service.ai.strategy;

import com.example.xunai.config.AiModelConfig;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@Component
@RequiredArgsConstructor
public class AiModelFactory {

    private final AiModelConfig aiModelConfig;
    private final Map<String, AiModelStrategy> strategies = new HashMap<>();

    public void registerStrategy(String modelType, AiModelStrategy strategy) {
        strategies.put(modelType, strategy);
        log.info("注册AI模型策略: {}", modelType);
    }

    public AiModelStrategy getStrategy(String modelType) {
        AiModelStrategy strategy = strategies.get(modelType);
        if (strategy == null) {
            log.warn("未找到模型策略: {}, 使用默认策略", modelType);
            strategy = strategies.get(aiModelConfig.getDefaultModel());
        }
        return strategy;
    }

    public AiModelStrategy getDefaultStrategy() {
        return getStrategy(aiModelConfig.getDefaultModel());
    }
}